{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\development tool\\Conda\\envs\\AI_Py3.7\\lib\\site-packages\\requests\\__init__.py:104: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (5.0.0)/charset_normalizer (2.0.4) doesn't match a supported version!\n",
      "  RequestsDependencyWarning)\n",
      "100%|██████████| 40/40 [17:04<00:00, 25.61s/it]\n"
     ]
    }
   ],
   "source": [
    "import nibabel as nib\n",
    "import numpy as np\n",
    "import os\n",
    "from tqdm import tqdm\n",
    "\n",
    "root = 'C:\\\\Users\\\\qqab1\\\\Downloads\\\\submit\\\\'\n",
    "\n",
    "org_files = os.listdir(root)\n",
    "out_root = 'C:\\\\Users\\\\qqab1\\\\Downloads\\\\submit_rjb\\\\'\n",
    "\n",
    "if not os.path.exists(out_root):\n",
    "    os.mkdir(out_root)\n",
    "\n",
    "for file in tqdm(org_files):\n",
    "    img = nib.load(root + file)\n",
    "    data = img.get_fdata()\n",
    "    \n",
    "    # 将data中等于11，12，13，15的值改为0\n",
    "    data[data == 11] = 0\n",
    "    data[data == 12] = 0\n",
    "    data[data == 13] = 0\n",
    "    data[data == 15] = 0\n",
    "\n",
    "    # 将data中等于14的值改为11\n",
    "    data[data == 14] = 11\n",
    "\n",
    "    img = nib.Nifti1Image(data, img.affine, img.header)\n",
    "    nib.save(img, out_root + file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(array([ 0,  1,  3,  4,  5,  6,  7,  9, 10, 11], dtype=int16), array([51582287,    92528,   121907,     9426,   874138,   183921,\n",
      "          54999,    50647,    39740,    74567], dtype=int64))\n",
      "(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15],\n",
      "      dtype=int16), array([51400992,   110664,    92528,   121907,     9426,     8558,\n",
      "         865580,   183921,    54999,    50647,    39740,     2257,\n",
      "           2557,    26051,    74567,    39766], dtype=int64))\n"
     ]
    }
   ],
   "source": [
    "import nibabel as nib\n",
    "\n",
    "data1 = nib.load('C:\\\\Users\\\\qqab1\\\\Downloads\\\\submit\\\\f8d197fc-b6f0-4b1e-adc3-ba3f373dcaf3.nii.gz').get_fdata().astype(np.int16)\n",
    "data2 = nib.load('C:\\\\Users\\\\qqab1\\\\Downloads\\\\submit1\\\\f8d197fc-b6f0-4b1e-adc3-ba3f373dcaf3.nii.gz').get_fdata().astype(np.int16)\n",
    "\n",
    "# data1 value count\n",
    "print(np.unique(data1, return_counts=True))\n",
    "print(np.unique(data2, return_counts=True))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "AI_Py3.7",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "11280b4ca1e46d3dd0b0a4b8f7ed15879720aa3162938ea890817f4de022b70e"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
